package com.rockfalldefence.sw.embark.client.page;

import net.binarymuse.gwt.client.ui.wizard.WizardPage;

import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.TextBox;
import com.rockfalldefence.sw.embark.client.RDEmbarkContext;

public class MaterialePage extends WizardPage<RDEmbarkContext> {
	public static final PageID PAGEID = new PageID();
	private FlowPanel panel;
	
	
	public MaterialePage() {
		panel = new FlowPanel();
	    panel.add(new HTML("<h1>Materiale Inerte per la realizzazione del rilevato</h1>"));
	    TextBox tb = null;
	    HorizontalPanel hp1 = new HorizontalPanel();
	    FlexTable t = new FlexTable();
	    Label lb = new Label("Angolo di attrito φ");
	    t.setWidget(1, 0, lb);
	    tb = new TextBox();
	    tb.addKeyPressHandler(new KeyPressHandler() {
	        public void onKeyPress(KeyPressEvent event) {
	          onlynumbers(event);
	        }
	    });
	    tb.setText("30");
	    tb.setWidth("40px");
	    tb.setName("angolo");
	    t.setWidget(1, 1, tb);
	    lb = new Label("(°)");
	    t.setWidget(1, 2, lb);
	    
	    lb = new Label("Peso specifico γ");
	    t.setWidget(2, 0, lb);
	    tb = new TextBox();
	    tb.addKeyPressHandler(new KeyPressHandler() {
	        public void onKeyPress(KeyPressEvent event) {
	          onlynumbers(event);
	        }
	    });
	    tb.setText("18");
	    tb.setWidth("40px");
	    tb.setName("gamma");
	    t.setWidget(2, 1, tb);
	    lb = new Label("(kN/m3)");
	    t.setWidget(2, 2, lb);
	    
	    lb = new Label("Coesione c");
	    t.setWidget(3, 0, lb);
	    tb = new TextBox();
	    tb.addKeyPressHandler(new KeyPressHandler() {
	        public void onKeyPress(KeyPressEvent event) {
	          onlynumbers(event);
	        }
	    });
	    tb.setText("0");
	    tb.setWidth("40px");
	    tb.setName("coesione");
	    t.setWidget(3, 1, tb);
	    lb = new Label("(kPa)");
	    t.setWidget(3, 2, lb);
	   
	    lb = new Label("Densità relativa ρr");
	    t.setWidget(4, 0, lb);
	    tb = new TextBox();
	    tb.addKeyPressHandler(new KeyPressHandler() {
	        public void onKeyPress(KeyPressEvent event) {
	          onlynumbers(event);
	        }
	    });
	    tb.setText("60");
	    tb.setWidth("40px");
	    tb.setName("dr");
	    t.setWidget(4, 1, tb);
	    lb = new Label("(%)");
	    t.setWidget(4, 2, lb);
	    hp1.add(t);
	    Image img = new Image("images/dettaglio_small.png");
	    hp1.add(img);
	    panel.add(hp1);

	    panel.add(new HTML("<h1>Materiale di rinforzo</h1>"));
	    
	    t = new FlexTable();
	    t.setHTML(0, 0, "&nbsp;");
	    t.setHTML(7, 5, "&nbsp;");
	    HorizontalPanel hp = new HorizontalPanel();
	    VerticalPanel vp = new VerticalPanel();
	    vp.setWidth("330px");
	    lb = new Label("Resistenza geogriglia a trazione");
	    vp.add(lb);
	    //t.setWidget(1, 0, lb);
	    ListBox dropBox = new ListBox(false);
	    dropBox.addItem("TT 045 SAMP => 45 kN/m","45");
	    dropBox.addItem("TT 060 SAMP => 60 kN/m","60");
	    dropBox.addItem("TT 090 SAMP => 90 kN/m","90");
	    dropBox.addItem("TT 120 SAMP => 120 kN/m","120");
	    dropBox.addItem("TT 160 SAMP => 160 kN/m","160");
	    //t.setWidget(1, 1, dropBox);
	    vp.add(dropBox);

	    vp.add(new HTML("<p>Geogriglie monorientate in HDPE, di resistenza a trazione dipendente dalle caratteristiche geometriche del rilevato, dalle caratteristiche geomeccaniche del terreno, dai carichi agenti sul rilevato stesso e da eventuali sollecitazioni sismiche.</p1>"));
	    hp.add(vp);
	    lb = new Label("Distanza geogriglie (m)");
	    lb.setHorizontalAlignment(Label.ALIGN_RIGHT);
	    lb.setTitle("Distanza fra geogriglie in metri");
	    t.setWidget(1, 0, lb);
	    tb = new TextBox();
	    tb.addKeyPressHandler(new KeyPressHandler() {
	        public void onKeyPress(KeyPressEvent event) {
	          onlynumbers(event);
	        }
	    });
	    tb.setWidth("40px");
	    tb.setName("dmax");
	    tb.setText("0.60");
	    tb.setTitle("Distanza fra geogriglie in metri");
	    t.setWidget(1, 1, tb);
	    lb = new Label("[Dg]");
	    t.setWidget(1, 2, lb);
	   
	    lb = new Label("Risvolto (m)");
	    lb.setHorizontalAlignment(Label.ALIGN_RIGHT);
	    lb.setTitle("Lunghezza minima geogriglie per Risvolto");
	    t.setWidget(2, 0, lb);
	    tb = new TextBox();
	    tb.addKeyPressHandler(new KeyPressHandler() {
	        public void onKeyPress(KeyPressEvent event) {
	          onlynumbers(event);
	        }
	    });
	    tb.setWidth("40px");
	    tb.setName("dmax");
	    tb.setText("1.50");
	    tb.setTitle("Lunghezza minima geogriglie per Risvolto");
	    t.setWidget(2, 1, tb);
	    lb = new Label("[Rg]");
	    t.setWidget(2, 2, lb);
	    hp.add(t);
	    panel.add(hp);
	    
	}

	protected boolean onlynumbers(KeyPressEvent event)
	{

		char inputC = event.getCharCode();
		Character chr = new Character(inputC);
		if (Character.isLetter(inputC)) {
			((TextBox) event.getSource()).cancelKey();
		} else if (chr.compareTo(new Character(','))==0) {
			((TextBox) event.getSource()).cancelKey();
		}
		return true;
	}

	@Override
	public Widget asWidget() {
		
		return panel;
	}

	@Override
	public PageID getPageID() {
		return PAGEID;
	}

	@Override
	public String getTitle() {
		return "Materiale";
	}

}
